<?php
session_start();

?>
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>海报制作后台注册</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="assets/css/admin.css">
    <link rel="stylesheet" href="assets/css/app.css">
</head>

<body data-type="login">

<div class="am-g myapp-login">
    <div class="myapp-login-logo-block  tpl-login-max">
        <div class="myapp-login-logo-text">
            <div class="myapp-login-logo-text">
                海报制作后台<span> 注册</span> <i class="am-icon-skyatlas"></i>

            </div>
        </div>

        <div class="login-font">
            <a href="./login.php"> <span> 登录</span> </a> or <i>注册 </i>
        </div>
        <div class="am-u-sm-10 login-am-center">
            <?php
            if ($_POST) {
                require_once './core/admin-sql.php';
                $sql = new AdminSql();
            if (isset($_POST['email']) && isset($_POST['password'])) {
                ?>
                <script src="assets/js/jquery.min.js"></script>
                <button type="button" class="am-btn am-btn-default">注册写入中...不要离开</button>
            <?php
            $result = $sql->signin($_POST['email'], $_POST['password']);
            if ($result === 0) {
            ?>
                <script>
                    $(".am-btn.am-btn-default").html("注册成功！3秒后跳转到登陆页面。");
                    setTimeout(go, 3000);

                    function go() {
                        window.location.href = "./login.php";
                    }
                </script>
            <?php
            } else {
            ?>
                <script>
                    alert(<?= $result ?>);
                    $(".am-btn.am-btn-default").html("注册失败，换个邮箱吧。3秒后重新注册");
                    setTimeout(go, 3000);

                    function go() {
                        window.location.href = "./signin.php";
                    }
                </script>
            <?php
            }
            }
            } else {
            ?>
                <form class="am-form" action="" method="post">
                    <fieldset>
                        <div class="am-form-group">
                            <input type="email" class="" id="doc-ipt-email-1" name="email" placeholder="输入电子邮件">
                        </div>
                        <div class="am-form-group">
                            <input type="password" class="" id="doc-ipt-pwd-1" name="password" placeholder="设置个密码吧">
                        </div>
                        <p>
                            <button type="submit" class="am-btn am-btn-default">注册</button>
                        </p>
                    </fieldset>
                </form>
                <?php
            }
            ?>
        </div>
    </div>
</div>

<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/app.js"></script>
<script src="./ajax/ajax-post.js"></script>
</body>

</html>